package com.yuncool.controller.v1.test;

import com.yuncool.auth.utils.SessionUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "权限测试接口")
public class AuthTestController {


	@ApiOperation(value = "无需登陆", httpMethod = "GET")
	@RequestMapping("/index/1")
	public String index1() {
		return "这个是主页任意用户";
	}

	@ApiOperation(value = "需登陆", httpMethod = "GET")
	@RequestMapping("/user/1")
	public String user() {
		return "这个是登陆才可访问";
	}

	@ApiOperation(value = "管理员才可访问", httpMethod = "GET")
	@PreAuthorize("hasRole('ADMIN')")
	@RequestMapping("/admin/1")
	public String admin() {
		return "这个是管理员才可访问";
	}

	@ApiOperation(value = "用户是否登陆判断", httpMethod = "GET")
	@RequestMapping("/index/2")
	public void index2() {
		if (new SessionUser().checkUserStatus()) {
			System.out.println("00000000");
		} else {
			System.out.println("11111111");
		}
	}
}
